Skip to content

[Task]32767979: Support AI Foundry by Handling GEN_AI_SYSTEM Attributes #41705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

Karlie-777
Copy link
Member

@Karlie-777 Karlie-777 commented Jun 20, 2025

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 21:37
@github-actions github-actions bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Jun 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for handling the GEN_AI_SYSTEM attribute by prefixing span types with GenAI | ... and using the attribute as a fallback for HTTP dependency targets.

  • Introduces fallback logic in _get_target_and_path_for_http_dependency to set the dependency target from gen_ai.system.
  • Updates _convert_span_to_envelope to prefix span types with GenAI | <system> for both CLIENT and InProc spans.
  • Extends tests in test_trace.py to cover internal spans carrying the gen_ai.system attribute.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_trace.py Adjusted client GenAI type assertion and added a new test for internal GenAI spans
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py Added a fallback to use gen_ai.system as the HTTP dependency target
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_exporter.py Prefixed CLIENT and InProc span types with `GenAI
Comments suppressed due to low confidence (2)

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_trace.py:768

  • [nitpick] The test name is quite long and blends 'client' and 'internal'. Consider renaming to something like test_internal_span_with_gen_ai_system_type to improve clarity.
    def test_span_to_envelope_client_internal_genai_type(self):

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py:207

  • The comment indentation under the elif gen_ai_attributes.GEN_AI_SYSTEM block is misaligned. Please adjust the indentation to match the surrounding code block for consistency.
         # If no fields are available to set target using standard rules, set Dependency Target to gen_ai.system if present

@hectorhdzg
Copy link
Member

We need to add dependency type and target logic for Dependency standard metrics here @lzchen can you confirm?

@@ -407,7 +407,7 @@ def _convert_span_to_envelope(span: ReadableSpan) -> TelemetryItem:
span.attributes,
)
elif gen_ai_attributes.GEN_AI_SYSTEM in span.attributes: # GenAI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These mappings take precedence over other mappings (ex. HTTP) even if their attributes are also present on the span.

This check needs to be moved up before the HTTP check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why it was added after other mappings originally?

Copy link
Member Author

@Karlie-777 Karlie-777 Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read the spec again, I assume it should mean gen_ai attribute value should override all other values (please correct me if I am wrong)
if we put gen_ai logic before http mapping, for example:

if attributes[gen_ai]
... // gen_ai mapping

if HTTP_REQUEST_METHOD in attributes // http mappings
... // other mappings

then the gen_ai value will be reset by other attribute values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so put gen_ai mapping after all other mappings, then gen_ai value will take precedence over other values

@lzchen
Copy link
Member

lzchen commented Jun 24, 2025

Please add an entry to the CHANGELOG and link the spec.

@Karlie-777
Copy link
Member Author

confirmed with @lzchen, no need to handle Dependency Standard Metrics, it will be auto handled by breeze endpoint

@@ -760,8 +778,57 @@ def test_span_to_envelope_client_gen_ai(self):
self.assertEqual(envelope.data.base_data.result_code, "0")

self.assertEqual(envelope.data.base_type, "RemoteDependencyData")
self.assertEqual(envelope.data.base_data.type, "az.ai.inference")
self.assertEqual(envelope.data.base_data.type, "N/A")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lzchen once gen_ai mappings is set at the top, this test case will be returning "N/A" instead of gen_ai. Just to confirm, it is what we are expecting.

if gen_ai_attributes.GEN_AI_SYSTEM in span.attributes: # GenAI
gen_ai_attributes_val = span.attributes[gen_ai_attributes.GEN_AI_SYSTEM]
if gen_ai_attributes_val:
data.type = _GEN_AI_ATTRIBUTE_PREFIX.format(gen_ai_attributes_val)
if _AZURE_SDK_NAMESPACE_NAME in span.attributes: # Azure specific resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an elif:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monitor - Exporter Monitor OpenTelemetry Exporter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants